package com.shen.shendimensmaker

import android.os.Bundle
import android.util.DisplayMetrics
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    var mTv : TextView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setupView()
    }

    private fun setupView() {
        mTv = findViewById<TextView>(R.id.tv)
        val metrics = resources.displayMetrics
        val builder = StringBuilder()
        builder.append("分辨率: ")
                .append(metrics.widthPixels)
                .append("x")
                .append(metrics.heightPixels)
                .append("\r\n")
                .append("屏幕密度: ")
                .append(metrics.density)
                .append("\r\n")
                .append("屏幕像素密度: ")
                .append(metrics.densityDpi)
                .append("\r\n")
                .append("屏幕宽高: ")
                .append("${(metrics.widthPixels * metrics.density + 0.5f).toInt()}")
                .append("x")
                .append("${(metrics.heightPixels * metrics.density + 0.5f).toInt()}")
        mTv?.text = builder.toString()
    }
}